home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume3 / activ next >
Encoding:
Internet Message Format  |  1989-02-03  |  7.9 KB

  1. Path: xanth!mcnc!gatech!mandrill!hal!ncoast!allbery
  2. From: marc@uunet.uu.net@tss.UUCP (Marc Meyer)
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i062: program for keeping timed transcript for activity logs
  5. Keywords: activities time-management status-reporting
  6. Message-ID: <307@tekbspa.UUCP>
  7. Date: 24 Jun 88 21:23:49 GMT
  8. Sender: allbery@ncoast.UUCP
  9. Reply-To: marc@uunet.uu.net@tss.UUCP (Marc Meyer)
  10. Organization: Teknekron Software Systems, San Jose, CA.
  11. Lines: 411
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. comp.sources.misc: Volume 3, Issue 62
  15. Submitted-By: "Marc Meyer" <marc@uunet.uu.net@tss.UUCP>
  16. Archive-Name: activ
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of shell archive."
  25. # Contents:  README activ.c
  26. # Wrapped by marc@alcatraz on Fri Jun 24 14:13:08 1988
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'README' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'README'\"
  30. else
  31. echo shar: Extracting \"'README'\" \(449 characters\)
  32. sed "s/^X//" >'README' <<'END_OF_FILE'
  33. X/*
  34. X**  ACTIV -- keep an activity typescript.
  35. X**    whenever the user types, will prepend the time if the typein has been
  36. X**    quiet for more than Interval, which defaults to 20 secs, but may be 
  37. X**    overridden with -i flag.  If over two hours, pust the entire time and 
  38. X**    date out.  Copies to a file.
  39. X**
  40. X**    Useage:
  41. X**        activ [-i interval] file
  42. X**
  43. X**    Compilation:
  44. X**        make activ -- no Makefile needed
  45. X**
  46. X**    History:
  47. X**        6/23/88 -- (marc) documented
  48. X**
  49. X*/
  50. END_OF_FILE
  51. if test 449 -ne `wc -c <'README'`; then
  52.     echo shar: \"'README'\" unpacked with wrong size!
  53. fi
  54. # end of 'README'
  55. fi
  56. if test -f 'activ.c' -a "${1}" != "-c" ; then 
  57.   echo shar: Will not clobber existing file \"'activ.c'\"
  58. else
  59. echo shar: Extracting \"'activ.c'\" \(5423 characters\)
  60. sed "s/^X//" >'activ.c' <<'END_OF_FILE'
  61. X
  62. X/*
  63. X**  ACTIV -- keep an activioty typescript.
  64. X**    whenever the user types, will prepend the time if the typein has been
  65. X**    quiet for more than Interval, which defaults to 20 secs, but may be 
  66. X**    overridden with -i flag.  If over two hours, pust the entire time and 
  67. X**    date out.  Copies to a file.
  68. X**
  69. X**    Useage:
  70. X**        activ [-i interval] file
  71. X**
  72. X**    History:
  73. X**        6/23/88 -- (marc) documented
  74. X**
  75. X*/
  76. X
  77. X# include    <stdio.h>
  78. X# include    <sgtty.h>
  79. X# include    <signal.h>
  80. X# include    <time.h>
  81. X# include    <errno.h>
  82. X# include    <ctype.h>
  83. X
  84. X# define    MAXLINE         350
  85. X
  86. Xstruct sgttyb    Ogttyb;
  87. Xchar        Erasec, Eofc, Killc, Wordc;
  88. Xchar        *Outfile;
  89. XFILE        *Outf;
  90. X
  91. Xmain(argc, argv)
  92. X{
  93. X    args(argc, argv);
  94. X    openFile();
  95. X    setty();
  96. X    setend();
  97. X    dialog();
  98. X}
  99. X
  100. XopenFile()
  101. X{
  102. X    if (!Outfile)
  103. X    {
  104. X        fprintf(stderr, "usage: activ file\n");
  105. X        exit (-1);
  106. X    }
  107. X    if (!(Outf = fopen(Outfile, "a+")))
  108. X    {
  109. X        perror(Outfile);
  110. X        exit (-1);
  111. X    }
  112. X    setlinebuf(Outfile);
  113. X}
  114. Xsetty()
  115. X{
  116. X    struct sgttyb    ngttyb;
  117. X    struct tchars    tchars;
  118. X    struct ltchars    lchars;
  119. X
  120. X    /* set cbreak mode */
  121. X    ioctl(0, TIOCGETP, &Ogttyb);
  122. X    ngttyb = Ogttyb;
  123. X    ngttyb.sg_flags |= CBREAK;
  124. X    ngttyb.sg_flags &= ~ECHO;
  125. X
  126. X    ioctl(0, TIOCSETP, &ngttyb);
  127. X    /* set editting characters */
  128. X    ioctl(0, TIOCGETC, &tchars);
  129. X    Eofc = tchars.t_eofc;
  130. X    ioctl(0, TIOCGLTC, &lchars);
  131. X    Wordc = lchars.t_werasc;
  132. X
  133. X    Erasec = Ogttyb.sg_erase;
  134. X    Killc = Ogttyb.sg_kill;
  135. X}
  136. Xsetend()
  137. X{
  138. X    int    endIt();
  139. X
  140. X    /* ensure that upon SIGINT, we dump things, and close the
  141. X     * file 
  142. X     */
  143. X    signal(SIGINT, endIt);
  144. X}
  145. XendIt()
  146. X{
  147. X    /* close file, reset tty mode to original mode */
  148. X    fclose(Outf);
  149. X    ioctl(0, TIOCSETP, &Ogttyb);
  150. X    exit (0);
  151. X}
  152. Xdialog()
  153. X{
  154. X    for (;;)
  155. X    {
  156. X        await_inp();
  157. X        fill_line();
  158. X    }
  159. X}
  160. Xawait_inp()
  161. X{
  162. X    int    fdt;
  163. X    int    err;
  164. X    extern    errno;
  165. X
  166. X    for (;;)
  167. X    {
  168. X        fdt = 1 << 0;
  169. X        err = select(32, &fdt, NULL, NULL, NULL);
  170. X        if (err != -1)
  171. X            return;
  172. X        if (errno != EINTR)
  173. X            perror("select");
  174. X    }
  175. X}
  176. X
  177. X# define    INTERVAL    20
  178. X
  179. Xchar    EntireLine[MAXLINE];
  180. Xint    LineBegin;
  181. Xint    OutCol;
  182. Xint    EdittedLine;
  183. Xint    ShownTill = 0;
  184. Xint    FirstCharOnLine = 1;
  185. Xchar    Line[MAXLINE];
  186. Xlong    LastTime;
  187. Xlong    ThisTime;
  188. Xint    Interval = INTERVAL;
  189. Xint    EofIn;
  190. X
  191. Xfill_line()
  192. X{
  193. X    gettime();
  194. X    get_any(Line, sizeof Line);
  195. X    if (gt_interval())
  196. X        FirstCharOnLine = 1;
  197. X    if (FirstCharOnLine)
  198. X    {
  199. X        dumpline();
  200. X        newline();
  201. X    }
  202. X    add_to_line(Line);
  203. X    line_edit();        /* edit and echo. */
  204. X    if (completeline())
  205. X    {
  206. X        dumpline();
  207. X    }
  208. X    if (eof_reached())
  209. X    {
  210. X        endIt();
  211. X        /*NOTREACHED*/
  212. X    }
  213. X}
  214. Xgettime()
  215. X{
  216. X    ThisTime = time(NULL);
  217. X}
  218. Xgt_interval()
  219. X{
  220. X    long    t = time(0);
  221. X
  222. X    return (t - LastTime > Interval);
  223. X}
  224. Xdumpline()
  225. X{
  226. X    int    n = strlen(EntireLine);
  227. X
  228. X    fputs(EntireLine, Outf);
  229. X    if (n != 0 && EntireLine[n-1] != '\n')
  230. X    {
  231. X        putc('\n', stdout);
  232. X        putc('\n', Outf);
  233. X    }
  234. X    EntireLine[0] = 0;
  235. X    EdittedLine = 0;
  236. X    LineBegin = 0;
  237. X    OutCol = 0;
  238. X    fflush(Outf);
  239. X}
  240. Xadd_to_line(s)
  241. Xchar    *s;
  242. X{
  243. X    strcat(EntireLine, s);
  244. X}
  245. Xnewline()
  246. X{
  247. X    struct tm    *tm;
  248. X    char        data[40];
  249. X    char        *timestring;
  250. X    char        *ctime();
  251. X    struct tm    *localtime();
  252. X    char        *s;
  253. X
  254. X    if (ThisTime - LastTime >= 2 * 60 * 60)
  255. X    {
  256. X        s = ctime(&ThisTime);
  257. X        s[strlen(s) - 1] = 0;    /* get rid of final newline */
  258. X        sprintf(data, "[%s] ", s);
  259. X    }
  260. X    else
  261. X    {
  262. X        tm = localtime(&ThisTime);
  263. X        sprintf(data, "[%02d:%02d:%02d] ", tm->tm_hour, tm->tm_min,
  264. X            tm->tm_sec);
  265. X        s = data;
  266. X    }
  267. X    add_to_line(data);
  268. X    LineBegin = strlen(EntireLine);
  269. X    EdittedLine = LineBegin;
  270. X    OutCol = 0;
  271. X    LastTime = ThisTime;
  272. X    fputs(data, stdout);
  273. X    fflush(stdout);
  274. X}
  275. Xline_edit()
  276. X{
  277. X    char    *i, *o;
  278. X
  279. X    for (i = &EntireLine[EdittedLine], o = i;
  280. X        *i; i++)
  281. X    {
  282. X        if (*i == Killc)
  283. X        {
  284. X            o = &EntireLine[LineBegin];
  285. X            EdittedLine = LineBegin;
  286. X            erase_col(OutCol);
  287. X            OutCol = 0;
  288. X        }
  289. X        else if (*i == Erasec)
  290. X        {
  291. X            --o; 
  292. X            if (OutCol > 0)
  293. X            {
  294. X                OutCol--;
  295. X                EdittedLine--;
  296. X                erase_col(1);
  297. X            }
  298. X        } else if (*i == Wordc)
  299. X        {
  300. X            if (OutCol <= 0)
  301. X                continue;
  302. X            /* skip initial spaces */
  303. X            if (isspace(o[-1]))
  304. X            {
  305. X                while (OutCol > 0 && isspace(*--o))
  306. X                {
  307. X                    OutCol--;
  308. X                    EdittedLine--;
  309. X                    erase_col(1);
  310. X                }
  311. X                if (OutCol != 0)
  312. X                    o++;
  313. X            }
  314. X            /* skip word */
  315. X            while (OutCol > 0 && !isspace(*--o))
  316. X            {
  317. X                OutCol--;
  318. X                EdittedLine--;
  319. X                erase_col(1);
  320. X            }
  321. X            if (OutCol != 0)
  322. X                o++;
  323. X        }
  324. X        else if (*i == Eofc)
  325. X        {
  326. X            EofIn++;
  327. X            break;
  328. X        }
  329. X        else if (isgraph(*i) || isspace(*i))
  330. X        {
  331. X            *o++ = *i;
  332. X            EdittedLine++;
  333. X            OutCol++;
  334. X            if (*i == '\n')
  335. X            {
  336. X                *i = 0;
  337. X                *--o = 0;
  338. X                dumpline();
  339. X                /* continue till end */
  340. X                line_edit();
  341. X            }
  342. X            else
  343. X                putchar(*i);
  344. X        }
  345. X        else
  346. X        {
  347. X            /* can't map the file output because doing it in place,
  348. X             * but can map the tty output, though i'll be confused
  349. X             * backspaceing!
  350. X             */
  351. X            EdittedLine += 1;
  352. X            OutCol += 2;
  353. X            putchar('^');
  354. X            putchar(*i | 0100);
  355. X            *o++ = *i;
  356. X        }
  357. X    }
  358. X    *o = 0;
  359. X    fflush(stdout);
  360. X    LastTime = ThisTime;
  361. X    FirstCharOnLine = 0;
  362. X}
  363. Xcompleteline()
  364. X{
  365. X    return (EntireLine[strlen(EntireLine) - 1] == '\n');
  366. X}
  367. Xeof_reached()
  368. X{
  369. X    return (EofIn);
  370. X}
  371. Xerase_col(i)
  372. X{
  373. X    while (--i >= 0)
  374. X        fputs("\b \b", stdout);
  375. X    fflush(stdout);
  376. X}
  377. Xget_any(buf, size)
  378. Xchar    *buf;
  379. Xint    size;
  380. X{
  381. X    int    n;
  382. X
  383. X    n = read(0, buf, size);
  384. X    if (n > 0)
  385. X        buf[n] = 0;
  386. X}
  387. Xargs(argc, argv)
  388. Xint    argc;
  389. Xchar    **argv;
  390. X{
  391. X    int    i;
  392. X
  393. X    for (argv++; *argv; argv++)
  394. X    {
  395. X        if (**argv != '-')
  396. X            Outfile = *argv;
  397. X        else switch ((*argv)[1])
  398. X        {
  399. X          case 'i':    /* set interval */
  400. X            if (!argv[1])
  401. X                break;
  402. X            i = atoi(*++argv);
  403. X            if (i > 0)
  404. X                Interval = i;
  405. X            break;
  406. X
  407. X          case '?':
  408. X            fprintf(stderr, "usage: activ [-i interval] file\n");
  409. X            break;
  410. X        
  411. X          default:
  412. X            fprintf(stderr, "activ: unknown flag `%s'\n",
  413. X                *argv);
  414. X        }
  415. X    }
  416. X}
  417. END_OF_FILE
  418. if test 5423 -ne `wc -c <'activ.c'`; then
  419.     echo shar: \"'activ.c'\" unpacked with wrong size!
  420. fi
  421. # end of 'activ.c'
  422. fi
  423. echo shar: End of shell archive.
  424. exit 0
  425.